package wec_wallet.ebo.com.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import wec_wallet.ebo.com.R;
import wec_wallet.ebo.com.bean.TransferRecordsDataBean;

/**
 * Created by Administrator on 2018/4/4.
 */

public class TransferRecordsAdapter extends BaseAdapter {
    Context context;
    List<TransferRecordsDataBean> list;
    LayoutInflater inflater;

    public TransferRecordsAdapter(Context context, List<TransferRecordsDataBean> list
    ) {
        this.context = context;
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.activity_list_item_transfer_records, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String status = list.get(position).getStatus();
        String state = context.getString(R.string.transfer_record_out_error);
        if (status.equals("1")) {
            state = context.getString(R.string.transfer_record_into_success);
        }
        if (status.equals("2")) {
            state = context.getString(R.string.transfer_record_into);
        }
        if (status.equals("3")) {
            state = context.getString(R.string.transfer_record_into_error);
        }
        if (status.equals("4")) {
            state = context.getString(R.string.transfer_record_out_success);
        }
        if (status.equals("5")) {
            state = context.getString(R.string.transfer_record_out);
        }

        holder.tvItemTransferRecordsState.setText(state);
        holder.tvItemTransferRecordsTime.setText(list.get(position).getCreated_at());
        holder.tvItemTransferRecordsNum.setText(list.get(position).getCoin_number()+" WEC");
        holder.tvItemTransferRecordsCoinName.setText(list.get(position).getCoin_species());
        holder.tvItemTransferRecordsCny.setText("≈" + list.get(position).getCoin_cny_num() + " CNY");
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.tv_itemTransferRecords_coinName)
        TextView tvItemTransferRecordsCoinName;
        @BindView(R.id.tv_itemTransferRecords_num)
        TextView tvItemTransferRecordsNum;
        @BindView(R.id.tv_itemTransferRecords_state)
        TextView tvItemTransferRecordsState;
        @BindView(R.id.tv_itemTransferRecords_cny)
        TextView tvItemTransferRecordsCny;
        @BindView(R.id.tv_itemTransferRecords_time)
        TextView tvItemTransferRecordsTime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
